<?php

function rpc( $json_request ) {
    global $PARAPARA;

    $req_param = $json_request->param;

    if(!$req_param) {
        return new RPC_Error($json_request->operation, "PARAM", "No params");
    };

    $since_id = $req_param->since_id;

    if(!isset($since_id) || !is_numeric( $since_id ) )
        $since_id = 0;

    $dbl = $PARAPARA->dblayer;

    $events   = $dbl->get_events( $since_id );

    usort($events, "Event::cmp");

    if(sizeof($events))
        $newest_id = $events[sizeof($events) - 1]->id;
    else
        $newest_id = $since_id;
    
    $rpc_retval = array( 'events' => $events, 'newest_id' => $newest_id );
    return new RPC_Response( $json_request->operation, $rpc_retval );

}

return rpc( $json_request );

?>
